<?php
class EducationsController extends AppController {

	var $name = 'Educations';
var $uses = array('Education','Language','Deptexam','Seniorscalexam');
	
	function index($id=null) {
		/*$this->Education->recursive = 0;
		$this->paginate = array(
        'conditions' => array('Education.user_id' => $this->Auth->user('id')),
        'limit' => 10
    );*/
	if($id==null)
		$id=$this->Auth->user('id');
	
		$this->set('educations',$this->Education->findAllByUserId($id));
		
		$this->set('languages', $this->Language->findAllByUserId($id));
		
		$this->set('deptexams', $this->Deptexam->findAllByUserId($id));
		
		$this->set('seniorscalexams', $this->Seniorscalexam->findAllByUserId($id));
		
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid education', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('education', $this->Education->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
		$this->data['Education']['user_id']=$this->Auth->user('id');
			$this->Education->create();
			if ($this->Education->save($this->data)) {
				$this->Session->setFlash(__('The education has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The education could not be saved. Please, try again.', true));
			}
		}
		$users = $this->Education->User->find('list');
		$this->set(compact('users'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid education', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Education->save($this->data)) {
				$this->Session->setFlash(__('The education has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The education could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Education->read(null, $id);
		}
		$users = $this->Education->User->find('list');
		$this->set(compact('users'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for education', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Education->delete($id)) {
			$this->Session->setFlash(__('Education deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Education was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>